package com.sc.nft.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.MallOrder;
import com.sc.nft.entity.vo.DistributionOrderVO;
import com.sc.nft.entity.vo.ExportOrderListVO;
import com.sc.nft.entity.vo.mall.AdminMallPageOrderVO;
import com.sc.nft.entity.vo.mall.AdminPageRefundOrderVO;
import com.sc.nft.entity.vo.mall.PageMallOrderVO;
import com.sc.nft.entity.vo.mall.PageMallPopularizeOrderVO;
import com.sc.nft.enums.SourceEnum;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * ip商城订单主表(sc_mall_order)数据Mapper
 *
 * @author Sun
 * @since 2023-05-09 10:46:38
 * @description 由 Mybatisplus Code Generator 创建
*/
@Mapper
public interface MallOrderMapper extends BaseMapper<MallOrder> {

    Integer getListByUserIdAndMallActivityIdAndStatusAndRefundStatus(@Param("userId") Long userId,@Param("mallActivityId") Long mallActivityId);

    Integer getMiniUserBuyCountByUserIdAndActivityId(@Param("miniUserId") Long miniUserId, @Param("mallActivityId") Long mallActivityId);

    /**
     * 分页条件查询订单列表
     *
     * @param page
     * @param userId
     * @param activityType
     * @param queryStatus
     * @return
     */
    Page<PageMallOrderVO> pageMallOrder(Page page, @Param("userId") Long userId, @Param("activityType") int activityType, @Param("queryStatus") Integer queryStatus, @Param("source") Integer source, @Param("wxMiniUserId") Long wxMiniUserId);


    /**
     * 分页条件查询推广订单列表
     * @param page
     * @param incomeUserId
     * @param incomeStatus
     * @return
     */
    Page<PageMallPopularizeOrderVO> pageMallPopularizeOrder(Page page,@Param("incomeUserId") Long incomeUserId,@Param("incomeStatus") int incomeStatus);

    /**
     * 分页条件查询后台订单列表
     *
     * @param page
     * @param activityType
     * @param orderNo
     * @param beginTime
     * @param endTime
     * @param payBeginTime
     * @param payEndTime
     * @param productName
     * @param status
     * @param payType
     * @param isRefund
     * @param userTel
     * @return
     */
    Page<AdminMallPageOrderVO> adminPageOrder(@Param("page") Page page, @Param("activityType") Integer activityType, @Param("orderNo") String orderNo, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime,
                                              @Param("payBeginTime") Date payBeginTime, @Param("payEndTime") Date payEndTime, @Param("productName") String productName, @Param("status") Integer status,
                                              @Param("payType") Integer payType, @Param("isRefund") Integer isRefund, @Param("userTel") String userTel, @Param("supplierId") Long supplierId, @Param("categoryName") String categoryName, @Param("orderSource") Integer orderSource);

    /**
     * 分页条件查询后台退款订单列表
     * @param page
     * @param orderNo
     * @param userTel
     * @param refundStatus
     * @return
     */
    Page<AdminPageRefundOrderVO> adminPageRefundOrder(@Param("page") Page page, @Param("orderNo") String orderNo, @Param("userTel") String userTel, @Param("refundStatus") Integer refundStatus, @Param("supplierId") Long supplierId);

    @Select("select ifnull(sum(total_price),0) from sc_mall_order where user_id = #{userId}  and status >1 and order_source = 1 and is_delete=0")
    BigDecimal getUserTotalPrice(Long userId);

    @Select("select ifnull(sum(refund_price),0) from sc_mall_order where user_id = #{userId} and refund_status=4 and status >1 and order_source = 1  and is_delete=0")
    BigDecimal getUserRefundPrice(Long userId);

    /**
     * 用户独立榜单,IP商城
     *
     * @param userId
     * @param beginTime
     * @param endTime
     * @return
     */
    BigDecimal getByUserIdSum(@Param("userId") Long userId, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);

    List<ExportOrderListVO> exportOrderList(@Param("type") Integer type);

    /**
     * 获取满足自动收货的订单列表
     * @param addDay
     * @return
     */
    List<MallOrder> getAutoConfirmMallOrder(@Param("addDay") Integer addDay);


    Page<DistributionOrderVO> getDistributionOrderVOAdminPage(@Param("page") Page page, @Param("orderNO") String orderNO, @Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("miniUserTel") String miniUserTel, @Param("orderStatus") Integer orderStatus, @Param("incomeStatus") Integer incomeStatus);
}
